package com.glsc.ngateway.platform.controller.cmdb;

import com.glsc.ngateway.common.api.platform.dto.user.PlatformUserDto;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.cmdb.CmdbDiskStandardDeviceStandardRelate;
import com.glsc.ngateway.platform.aspect.UserCache;
import com.glsc.ngateway.platform.service.cmdb.CmdbDiskStandardDeviceStandardRelateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

import static com.glsc.ngateway.common.api.common.enums.DictConstant.CMDB_DISK_STANDARD_DEVICE_STANDARD_RELATE;

@RestController
@Api(value = "磁盘标准设备标准关联管理", tags = {"磁盘标准设备标准关联管理"})
public class CmdbDiskStandardDeviceStandardRelateController {

    @Autowired
    private CmdbDiskStandardDeviceStandardRelateService cmdbDiskStandardDeviceStandardRelateService;
    @Autowired
    private UserCache userCache;
    @Autowired
    private HttpServletRequest request;

    /**
     * 查询磁盘标准设备标准关联
     * @param params
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/diskStandardDeviceStandardRelate/search")
    @ApiOperation(value = "查询磁盘标准设备标准关联", notes = "查询磁盘标准设备标准关联")
    public PlatformResponse<Object> searchDiskStandardDeviceStandardRelate(@RequestBody Object params) {
        Object result = cmdbDiskStandardDeviceStandardRelateService.search(CMDB_DISK_STANDARD_DEVICE_STANDARD_RELATE, params);
        return PlatformResponse.successData(result);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/diskStandardDeviceStandardRelate/addOrUpdate")
    @ApiOperation(value = "修改磁盘标准设备标准关联", notes = "修改磁盘标准设备标准关联")
    public PlatformResponse<Void> addOrUpdateDiskStandardDeviceStandardRelate(@RequestBody CmdbDiskStandardDeviceStandardRelate cmdbDiskStandardDeviceStandardRelate) {
        PlatformUserDto user = userCache.get(request);
        String account = user.getUsername();
        cmdbDiskStandardDeviceStandardRelateService.addOrUpdateDiskStandardDeviceStandardRelate(cmdbDiskStandardDeviceStandardRelate, account);
        return PlatformResponse.successMsg("处理成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "/diskStandardDeviceStandardRelate/delete")
    @ApiOperation(value = "删除磁盘标准设备标准关联", notes = "删除磁盘标准设备标准关联")
    public PlatformResponse<Void> deleteDiskStandardDeviceStandardRelate(@RequestBody CmdbDiskStandardDeviceStandardRelate cmdbDiskStandardDeviceStandardRelate) {
        PlatformUserDto user = userCache.get(request);
        String account = user.getUsername();
        cmdbDiskStandardDeviceStandardRelateService.deleteDiskStandardDeviceStandardRelate(cmdbDiskStandardDeviceStandardRelate, account);
        return PlatformResponse.successMsg("删除成功");
    }

    @RequestMapping(method = RequestMethod.POST, value = "/diskStandardDeviceStandardRelate/deleteList")
    @ApiOperation(value = "批量删除磁盘标准设备标准关联", notes = "批量删除磁盘标准设备标准关联")
    public PlatformResponse<Void> deleteListDiskStandardDeviceStandardRelate(@RequestBody List<Integer> codes) {
        PlatformUserDto user = userCache.get(request);
        String account = user.getUsername();
        cmdbDiskStandardDeviceStandardRelateService.deleteByCodeList(codes, account);
        return PlatformResponse.successMsg("删除成功");
    }
}
